package com.service.tools;

import java.security.MessageDigest;

import com.service.other.Logger;

public class StringParser {
	
	public static int parseInt(String s) {
		try{
			return Integer.parseInt(s);
		}catch(Exception e){
			Logger.err(e);
			return 0;
		}
	}
	
	public static long parseLong(String s){
		try{
			if (null == s) {
				return 0;
			}
			return Long.parseLong(s);
		}catch(Exception e){
			Logger.err(e);
			return 0;
		}
	}
	
	/**
	 * MD5加密
	 * @param s
	 * @return
	 */
	public static String parseMD5(String s) {
	    String result = "";
	    try {
	        MessageDigest md = MessageDigest.getInstance("MD5");
	        md.update(s.getBytes());
	        byte b[] = md.digest();
	        int i;
	        StringBuffer buf = new StringBuffer("");
	        for (int offset = 0; offset < b.length; offset++) {
	            i = b[offset];
	            if (i < 0)
	                i += 256;
	            if (i < 16)
	                buf.append("0");
	            buf.append(Integer.toHexString(i));
	        }
	        result = buf.toString();
	    } catch (Exception e) {
			Logger.err(e);
		}
	    return result.toUpperCase();
	}

}